
Ccay.UI.XDialog = {};
﻿/**@description XDialog 组件*/
( function ( Dialog ) {
	var config = {
		
	//	id : null,
		title: "ccay.common.label.select",
		target : "#ccayContentPanel",//弹出层html，将添加的位置，默认添加到ccay的内容区域，如果指定为null，则添加到body
		 
		/** 宽度与位置 */
		width : 0, 	
		height : 0,	
		maxHeight : 0, 
		top : 0,	
		fixY : 70,
		fixX : 20,
	//	left:0,
		
	//	url : null,  //dialog 内容通过指定的url方式载入
		load : true, //默认采用load方式载入页面
	//	content : null, //html 内容字符串，直接通过使用html初始化dialog，如果同时传递了context与url，将优先使用content，
		/** dialog 按钮定义 */
		buttons:[],
		
		modal : true,
	//	fixed : false,//如果fixed为true则，不能拖拽，并且弹出框停总留在屏幕中间
		show : true, //默认显示
		showFoot : true,
		showCloseImg : true,
		btnAlign : "right",
		drag : true,
		
		/** 事件 */
		handler : {},
		closeRemove :true,  //关闭弹出框后，将dom元素移除，默认为true，设置为false的时候，关闭只会隐藏该弹出框
		reSizable:false // 是否可以拖拽放大缩小，默认关闭
	//	fnLoad : null,
	//	fnBeforeLoad : null,
	//	fnClose : null,
	//	fnBeforeClose : null,
	//	fnDraged : null,
	//	fnDestory : null
	//  fnReopen :null
	};
   

   var factory = Dialog.Factory = {
   	

   		
    	//初始化样式设置
    	initStyle : function( dialog, op ){
			var dom = dialog.dom;
    		if( !op.drag || op.fixed ){
				dom.find( ".ccay-dialog-title" ).css( "cursor","default" )
			}
			op.height && dialog.getBody().css( {height : op.height} );
			op.maxHeight && dialog.getBody().css( {maxHeight : op.maxHeight} );
			op.minHeight && dialog.getBody().css( {minHeight : op.minHeight} );
			//为表格个性化设置弹出框设置最大高度
			if(op.title === "ccay.common.igrid.customSetting"){
    			dialog.getBody().css({maxHeight:"380px"});
    		}
			if( op.modal ){
				var z= 1000 + Dialog.Helper.lives * 10;
				dom.css( "z-index", z )
				dialog.getOverlay().show().css( "z-index", z - 1 );//模式窗口需要遮罩层
				Dialog.Helper.lives ++ ;
			}
			// infotip 模式要修改z-index add by l00195395
			if(op.infoTip){
				var z= 995 + Dialog.Helper.lives * 10;
				dom.css( "z-index", z );
			}
			if( op.fixed ){
				dom.addClass( "fixed" );
			}
			
			if( !op.showCloseImg ){
				dom.find("div.ccay-dialog-close").hide();
			}

    	},
    	
    	updateStyle : function( dialog, op ){
    		var dom = dialog.dom;
			var win = $( window ), scrollTop = op.fixed ? 0 : win.scrollTop(),
			width = ( op.width * 1 ||  dom.width() ) + op.fixX,
			height= op.height || dom.height();
			
			var top=( op.top || ( win.height()- op.fixY - height ) / 2 ) + scrollTop;
			var left = op.left || ( win.width() - op.width ) / 2;
			top= top < 0 ? 0 : top;
			dom.css( {top : top,  left : left, width : width} );
			//如果默认显示，则显示dialog
			if( op.show ){
				dom.show();
			}
    		dialog.focus();
    	}

    }



	//结构构造器
    factory.Builder = {
        init: function ( dialog, op ) {
            var html = [];
            this.buildHead( html, op );
            this.buildBody( html, op );
            op.showFoot && this.buildFoot( html, op );
            op.reSizable && this.buildResizable(html, op);
          	dialog.dom.html( html.join( '' ) );
			var target= op.target && $( op.target ).length ? $( op.target ) : document.body;
			dialog.dom.appendTo(target); 
            op.showFoot && this.buildFootContent( dialog, op );
            if(op.modal){
         	   this.buildFocusInput( dialog, op );
            }
            dialog.getHead().find( "div.ccay-dialog-title" ).prepend( $i18n( op.title ) );
            this.buildBodyContent( dialog, op );
            this.buildOverlay( dialog, op );
			return dialog;
        },
        buildHead: function ( html, op ) {
        	if(op.showHead===false){
            	html.push( "<div class='ccay-dialog-close'><div class='ccay-dialog-closeimg'></div></div>" );
        	}else{
				html.push( "<div class='ccay-dialog-head unselect'><div class='ccay-dialog-close'>");
				html.push("<div class='ccay-dialog-closeimg'></div></div>");
				//弹出框最大化
				if(op.reSizable){
					html.push("<div class='ccay-dialog-max'><div class='ccay-dialog-maximg'></div></div>");
				}
				html.push("<div class='ccay-dialog-title'></div></div>");
        	}
        },
        buildBody: function ( html, op ) {
            html.push( "<div class='ccay-dialog-body'></div>" );
        },
        buildFoot: function ( html, op ) {
            html.push( "<div class='ccay-dialog-foot'></div>" );
        },
        buildResizable : function(html, op){
			//var handle = ["n","e","s","w","se","sw","ne","nw"];
			var handle = ["e","s","se"];
			$.each(handle, function(i, value){
			if(value == "se"){
				value = "se resizable-icon";
			};
			html.push('<div class="ccay-dialog-resizable resizable-'+ value +'"></div>');
			})
        },
		buildFootContent : function( dialog, op ){
			var btnHtml = "<input type=button   value='{0}' class='ccay-dialog-button {1}'>";
			// 如果配置的是图标按钮
			if(op.imgBtn){
				btnHtml ='<span class="ccay-button" tabIndex=0><a class="ccay-icon {1}"></a><label>{0}</label></span>';
			};
			var foot = dialog.getFoot(), allButtons = [];
			if(op.buttons){
				allButtons = allButtons.concat(op.buttons);
			}
			if( typeof op.okClick == "function" ){
				allButtons.push({text : op.okText || "ccay.common.button.ok", icon : "confirm", onClick : op.okClick, cls:"ccay-icon"});
			}
			if ( typeof op.okClick == "function" || op.cancelClick ) {
				allButtons.push({text : op.cancelText || "ccay.common.button.cancel", icon : "cancel",cls:"ccay-icon" , onClick : typeof op.cancelClick =="function" ? op.cancelClick : function(){
					this.close(dialog, dialog.op); 
				}})
			}
			$.each(allButtons,function(i, btn){
				btn.icon = btn.icon || ""; 
				$(btnHtml.formatValue($i18n(btn.text), btn.icon)).addClass( btn.cls ).bind( "click",function(e){
					 btn.onClick && btn.onClick.call(dialog,e);
					 e.stopPropagation();
				}).appendTo( foot );
			});
			//设置按钮位置
			foot.addClass(op.btnAlign);
		},
		
		buildFocusInput :function( dialog, op ){
			var head = dialog.getHead(),foot = dialog.getFoot();
			//200947 add commit ： 让弹出框获取焦点。不然像 按 Tab 键之类的，焦点不会在弹出框上 
			head.find( "div.ccay-dialog-title" ).append( $.create( "input","ccay-dialog-focus","z","button" ) );
			foot.append( $.create( "input","ccay-dialog-focus","focusInputEnd","button" ) );
		},
		
		
		/** 根除参数，初始化 弹出层的内容区域
		 * @param dialog {object} 弹出层jquery对象
		 * @param op {Object} 用户传递的参数设置对象
		 */
		buildBodyContent : function( dialog, op ){
			
			var body = dialog.getBody();
			
			//载入内容前执行方法 fnBeforeLoad
			op.fnBeforeLoad && op.fnBeforeLoad.call(dialog, dialog.dom, op );
			//根据参数设置，得到加载内容的方式
			var loadType= op.content ? "dom" : ( op.load ? "ajax" : "iframe" ) ;
			//分别处理 dom ajax iframe 三种方式载入内容 
			if( loadType == "dom" ){
				
				typeof op.content == "string" ?  body.html( op.content ) : body.append( $(op.content).show() ); //将dom内容加入到body
				op.fnLoad && op.fnLoad.call(dialog, dialog.dom, op ); ////载入html内容之后执行方法 fnLoad
				
			}else if( loadType === "ajax"  && op.url ){
				op.ajax = {};
				op.autoLoad = false;
				//开始时间
				var startTime = new Date();
				body.ccayLoad( op.url,function(){
					op.fnLoad && op.fnLoad.call(dialog, dialog, op ); 	//载入html内容之后执行方法 fnLoad
					//结束时间
					var endTime = new Date();
				}, true)
			}else if( loadType === "iframe" && op.url ){
				body.html( "<iframe src='{0}' class='ccay-dialog-iframe' width=100% height={1}px  frameborder=0 />".formatValue( op.url, op.height-10 ) );
			}
		
		},
		
		buildOverlay : function( dialog, op ){
			if(op.modal){
				var overlay=$( "#ccay_dialog_overlay" );
				if( overlay.length == 0 ){
					overlay=$( '<div class="ccay-overlay" id="ccay_dialog_overlay"></div>' ).prependTo( $( document.body ) ).click( function(){
						Dialog.Helper.focus();
					} );
				}
				return overlay;
			}
		}
		
		
    };


    factory.EventBinder = {
        init: function ( dialog, op ) {
            this.bindDrag( dialog, op );
            this.bindClick( dialog, op );
            this.bindFocus( dialog, op );
            this.bindScroll( dialog, op );
            op.reSizable && this.bindReSize( dialog, op );
        },
        
        bindDrag : function( dialog, op ){
        	if( op.drag  && !op.fixed ){
        		var dom = dialog.dom;
 				dom.find( "div.ccay-dialog-title" ).drag( {
					handler : dom,
					onDroped : function(){
						dialog.focus();
						op.fnDraged && op.fnDraged.call(this, dialog.dom, op );
					}
				} )
        	
        	}
        },

        bindClick: function( dialog, op ){
        	dialog.dom.find( "div.ccay-dialog-closeimg" ).click( function(event){
        		event && event.stopPropagation && event.stopPropagation();
        		dialog.close();
        	} );
        	
        	dialog.getHead().find(".ccay-dialog-max").click( function(){
        		$(dialog.dom).css("height", "").fullScreen();
        		
        		var maxIcon = $(this).children(".ccay-dialog-maximg");
        		maxIcon.toggleClass("small-maximize");
        		
        		// 修复弹出框最大化时，body高度未变。add by l00195395 2014/2/22
        		var dialogHead = dialog.getHead(),
					dialogFoot = dialog.getFoot(),
					dialogBody = dialog.getBody(),
					headFootHeight = dialogFoot.outerHeight() + dialogHead.outerHeight();
        		if(maxIcon.hasClass("small-maximize")){
        			dialogBody.data("originalHeight" ,dialogBody.height()); // 保存原始大小
        			dialogBody.height($(dialog.dom).height() - headFootHeight - 9);
        		}else{
        			// 设置原始大小
        			dialogBody.height(dialogBody.data("originalHeight"));
        		}
        	});
        },
        
		bindFocus: function( dialog, op ){
			dialog.dom.find( "#focusInputEnd" ).focus( function(){
				dialog.focus();
			} );
			if(op.infoTip){
				$(document).bind("mousedown.infoTip",function(e){
					// 锁定时 | 删除操作确认,信息框不关闭
					if(dialog.dom.find(".ccay-dialog-pinimg.pin").length > 0 || dialog.dom.data("notClose")){
						return;
					}
					// 鼠标点击信息框外时关闭信息框
					if(dialog.dom.find(e.srcElement).length < 1){
						dialog.close();
						$(document).unbind("mousedown.infoTip");
					}
				});
			};
		},
		// 拖动放大缩小
		bindReSize: function(dialog, op){
			$(".ccay-dialog-resizable").mousedown(function(e){
				// 禁用文本拖动事件
				$(document).bind("selectstart.resize",function(){
					return false;
				});
				var me  = $(this),
					dialogDom = dialog.dom,
					dialogLeft = dialogDom.offset().left, 
					dialogTop = dialogDom.offset().top,
					dialogHead = dialog.getHead(),
					dialogFoot = dialog.getFoot(),
					dialogBody = dialog.getBody(),
					headFootHeight = dialogFoot.outerHeight() + dialogHead.outerHeight(),
					minHeight = op.minHeight,
					maxHeight = op.maxHeight,
					fixHeight = 9; //高度修复数,为上下padding和border
				// dialog的最大最小高度限制 
				if(minHeight){
					minHeight = minHeight + headFootHeight + fixHeight;
				};
				if(maxHeight){
					maxHeight = maxHeight + headFootHeight + fixHeight;
				}
				// 鼠标按住拖动事件
				$(document).bind("mousemove.resize", function(e){
					var x = e.clientX + $(window).scrollLeft(),
						y = e.clientY + $(window).scrollTop(),// scrollTop浏览器滚动高度
						newWidth = x - dialogLeft,
						newHeight = y - dialogTop;
					
					// 最小最大高度限制100
					newWidth < 100 && (newWidth = 100);
					newHeight < 100 && (newHeight = 100);
					// 和设置的最大最小高度比较处理
					if(minHeight && (newHeight < minHeight)){
						newHeight = minHeight;
					};
					if(maxHeight && (newHeight > maxHeight)){
						newHeight = maxHeight;
					};
					// dialog dom 横向竖向角落拖动处理
					if(me.hasClass("resizable-e")){
						dialogDom.css({width: newWidth});
						return;
					} else if(me.hasClass("resizable-s")){
						dialogDom.css({height: newHeight});
					} else {
						dialogDom.css({width: newWidth, height: newHeight});
					}
					// dialog BODY 的高度
					dialogBody.css({height : newHeight - headFootHeight - fixHeight});
				});
				
				// 鼠标按键停止 卸载事件
				$(document).mouseup(function(){
					$(document).unbind("mousemove.resize").unbind('selectstart.resize');
				});
			});
		},
		//弹出层滚动条事件
		bindScroll : function(dialog, op){
			dialog.getBody().scroll(function(){
				var popDiv = Ccay.Page.getContentPanel().children("#popupPanel").children(".ccay-popup:visible");
				if(popDiv){
					popDiv.filter(":not(.ccay-popup-lock)").each(function(){
						Ccay.UI.popupClose($(this));
					});
				}
				// 日历
				$("#ccay_calendar_div:visible").each(function(){
					Ccay.UI.popupClose($(this));
				});
			});
		}
    }
    
    
	Dialog.Helper = {
		
		index : 0,
		zIndex : 1000,
		lives : 0,//用来保存存活的modal dialog数量
		idprex : "ccay_dialog",
		

		
		newId : function(){
			return this.idprex + ( ++this.index );
		},
		
		close : function( all ){
			all ? $( "div.ccay-dialog" ).remove() : $( "div.ccay-dialog.modal" ).remove();
			getDialog().lives = 0;
			$( "#ccay_dialog_overlay" ).hide();
		},
		
		/** 将焦点交给指定dialog，如果没传参数，则将焦点交予最顶层的dialog */
		focus : function(){
			$( "div.ccay-dialog.modal:last" ).find( "#focusInputBegin" ).focus();;
		}

	};
	
	
    var manager = {
    	
		/** @description 获取头部容器
	     *  @return {JQDom}
	     */
		getHead: function (){
	        return DomClass.getProp( this, this.dom, 'head', '.ccay-dialog-head' );
	    },
	    /** @description 获取中部容器
	     *  @return {JQDom}
	     */
		getBody: function (){
            return DomClass.getProp( this, this.dom, "body", ".ccay-dialog-body" );
        },
        /** @description 获取底部容器
	     *  @return {JQDom}
	     */
        getFoot: function (){
	        return DomClass.getProp( this,this.dom, 'foot', '.ccay-dialog-foot' );
	    },
		
	    getOverlay : function (){
	    	return $( "#ccay_dialog_overlay" );
	    },

		focus : function(){
			this.dom.find( "#focusInputBegin" ).focus();
		},
		
		fixPosition : function(){
			factory.updateStyle( this, this.op );
		},
		fullScreen : function(container, fullHeight, isFull){
        	if(isFull){
	   			//container.css("height") && container.data("oh", container.css("height"));
	   			container.css("width") && container.data("ow", container.css("width"));
	   			container.css("left") && container.data("ol", container.css("left"));
	   			container.css("top") && container.data("ot", container.css("top"));
	   			container.css("width", "").css("left", "").css("top", "");   			
	   		}else{
	   			//container.data("oh") && container.css("height",container.data("oh"));
	   			container.data("ow") && container.css("width",container.data("ow"));
	   			container.data("ol") && container.css("left",container.data("ol"));
	   			container.data("ot") && container.css("top",container.data("ot"));
	   		}
        },
		/**  关闭 */
		close : function(){
			//清除选择，兼容IE8浏览器
			//document.selection && document.selection.empty();
			var op = this.op;
			
			// 最大化后处理 add by l00195395 2014.2.25
			if(op.reSizable && this.getHead().find(".ccay-dialog-maximg.small-maximize").length){
				$(this.dom).fullScreen();
			}
			
			if(op.status !=="closing"){
				if( typeof op.fnBeforeClose == "function" ){
					if( op.fnBeforeClose.call( this, this.dom, op ) !== false ){
						op.status = "closing";
						op.fnClose && op.fnClose.call( this, this.dom, op ); 
						this.destory( this, op ); 
						//修复IE8浏览器单选弹出框点击报错
						try{document.selection && document.selection.empty();}catch(ex){}
					}
				}else{
					op.status = "closing";
					op.fnClose && op.fnClose.call( this, this.dom, op ); 
					this.destory( this, op );
				}
			}else{
				this.destory( this, op );
			}
		},
		
		/** 销毁dialog */
		destory : function(){
			var op = this.op;
			if(op.closeRemove){
				op.content = null;
				op.fnDestory && op.fnDestory.call( this );
				this.dom.remove();
			}else{
				this.dom.hide();
			}
			//当全部弹出框都关闭才取消遮罩层
			if( op.modal ){
				Dialog.Helper.lives -- ;
				if( Dialog.Helper.lives > 0 )
					this.getOverlay().css( "z-index", 1000 + Dialog.Helper.lives * 10 - 11 );
				else{
					this.getOverlay().hide();
				}
			}
			this.op.infoTip && $(document).unbind("mousedown.infoTip");
		}
		
		


	};
    
    var flow = {


		init : function( dialog, op ){
			
		},
    	build : function( dialog, op )
    	{
    		factory.Builder.init( dialog, op );
    	},
    	bindEvent : function( dialog, op ){
    		factory.EventBinder.init( dialog, op );
    	},
    	initComplete : function( dialog, op ){
    		
    		factory.initStyle( dialog, op );
    	},
		initAjax : function( dialog, op ){
			this.base.complete.call( this,dialog,op );
		},
		complete: function( dialog, op ){
			factory.updateStyle( dialog, op );
			op.handler.complete.fire( dialog, op );
		}
    };
    
    
    var XDialog = Ccay.UI.XControl( "XDialog", flow, config, manager );
    
	/** dialog 初始化*/
     $.fn.dialog = function ( op ) {
     	if(!op){
     		op = {};
     	}
       	if(this.length > 0 &&  !op.closeRemove){
     		op.closeRemove = false;
     	}
     	op = $.extend( {content : this[0]},op );
     	//增加全局设置按钮位置，本地优先
     	op.btnAlign =op.btnAlign || Ccay.UI.Config.dialog.btnAlign;
     	//end add
		if(this.attr("dialogInit")){
			var dialog = this.parents(".ccay-dialog:first").manager(), op = dialog.op;
			factory.initStyle(dialog, op);
			factory.updateStyle(dialog, op);
			op.fnReopen && op.fnReopen.call( dialog, dialog.dom, op ); 
			return dialog.dom;
		}
     	op.id = op.id || Dialog.Helper.newId();
     	var dom = $.create( "div","ccay-dialog ccay-popup",op.id ).attr("init",true);
     	this.attr("dialogInit",true);
        var dialog = new XDialog( dom, op);
        op.inited = true;
        return dom;
    }
    
	/** 移除页面所有dialog 或 modalDialog*/
	$.dialogClose = function( all ){
		var dialogs =  	all ? $( "div.ccay-dialog" ) : $( "div.ccay-dialog.modal" );
		dialogs.each( function(){
			$(this).manager().close();
		} )
	};
	
	$.fn.getParentDialogManager = function(){ 
		return this.parents(".ccay-dialog:first").manager();
	};
	 
	

    /** MessageBox 插件部分 */
	Ccay.UI.XControl.addPlugin( "XDialog", "messageBox", {
	    preInit: function ( dialog, op ) {
	    	var fnClose = op.fnClose;
    		op.fnClose = function(dom,op){
    			$(document).unbind("keydown.message.lock");
    			fnClose && fnClose.call(this,dom,op);
    		};
	    	if( op.messageBox &&  op.messageBox.type){
		    	//保持单实例
		    	var msgbox = $("div.ccay-dialog.message-box.onlyone");
		    	if( msgbox.length > 0 ){
		    		msgbox.manager().close();
		    	}
				messageBox[op.messageBox.type].preInit( dialog, op );
	    	}
	    },
	    
	    build : function( dialog, op ) {
	    	if( op.messageBox &&  op.messageBox.type){
	    		$(document).unbind("keydown.message.lock").bind("keydown.message.lock",function(e){
	    			if(e.keyCode==9){
	    				return false;
	    			}
	    		});
	    		var dom = dialog.dom.addClass("message-box");
	    		op.handler.complete.add(messageBox[op.messageBox.type].complete);
	    	}
	    }
	 } );
	 
	 
	 var messageBox = {
	 	
	 	/** 弹出提示框 消息插件(success|error|warn|question|confirm) */
		message : {
		 	//预初始化，参数处理
		    preInit: function ( dialog, op ) {
		    	// 消息插件模板与按钮设置
	    		op.title = op.title && op.title!==config.title ? op.title : $i18n( Ccay.UI.Config.messageTitle.title );
	    		op.target = null;
	    		op.content =( "<div class='ccay-dialog-message'><div class='ccay-dialog-image image-{0}'></div><div class='ccay-dialog-content'>" +
	    		(op.messageBox.encode ? $i18n( "" + op.content ).encode() :  $i18n( "" + op.content )).replace( /\n/g,"<br/>" ) + "</div></div>" ).formatValue( op.messageBox.style );
	    		op.buttons = [{icon:"confirm",text : "ccay.common.button.ok", cls : "default", onClick : function(){ dialog.close();}}] ;
	    		op.imgBtn = true; // 指定为图标按钮
		    },
		    
		    //创建后，事件绑定
		    complete : function( dialog, op ) {
		    	//var dom = dialog.dom.addClass("message-box");
		    	var dom = dialog.dom.addClass("onlyone");
		    	// 提高优先级 比ccay-selector的4000大
		    	dom.css( "z-index", 4010 );
		    	var defaultBtn;
		    	if(op.imgBtn){
		    		defaultBtn = dom.find('.ccay-button.default');
		    	}else{
		    		defaultBtn = dom.find('input.default');
		    	};
				dom.bind( 'keydown', function( e ) {
					var code = e.keyCode;
					if( code == 27 ||code == 13 ){
						defaultBtn.click();
					}
				} )
				defaultBtn.focus();
				
			
		    }
		},
		
		//弹出确认框插件
		confirm : {
	 
	 		preInit : function( dialog, op){
		    	// 消息插件模板与按钮设置
	 			op.result = false;
	 			op.target = null;
	    		op.title = op.title && op.title!==config.title ? op.title : $i18n( Ccay.UI.Config.messageTitle.confirm );
	    		op.content = "<div class='ccay-dialog-message'><div class='ccay-dialog-image image-question'></div><div class='ccay-dialog-content'>{0}</div></div>".formatText(op.messageBox.encode ? $i18n( op.content ).encode() : op.content);
				op.okClick = function(){ op.result = true; dialog.close() };
				op.cancelClick = function(){ op.result = false; dialog.close() };
				op.imgBtn = true; // 指定是图标按钮
	 		},
		    
		    //创建后，事件绑定
		    complete : function( dialog, op ) {
		    	var dom = dialog.dom,
		    		foot = dialog.getFoot(),
		    		footBtn = foot.find(".ccay-button,input:button");
		    	var no = op.messageBox.focusYes ? 0 : 1;
				footBtn.eq(no).addClass( "default" ).focus();
				// 提高优先级 比ccay-selector的4000大
				dom.css( "z-index", 4010 );
				dom.bind( "keydown", function(e) {
					var code = e.keyCode;
					if(code == 13){
						//按键  回车 触发默认焦点按钮
						if(footBtn.filter(":focus").length == 1){
							footBtn.filter(":focus").click();
						}else{
							footBtn.eq(no).click();
						}
					}else if(code == 89){
						//按键 y  触发ok按钮 
						footBtn.eq(0).click();
					}else if(code==27 || code == 78){
						//按键  esc 或 n，触发cancel按钮
						footBtn.eq(1).click();
					}
				});
		    }
	 
		 }
		 
	 }
	 
	 
	 Ccay.UI.XControl.addPlugin( "XDialog", "toolbar", {
	    build : function( dialog, op ) {
	    	if( typeof op.toolbar == "object" ){
	    		dialog.getFoot().ccayToolbar(op.toolbar).find("#focusInputEnd").appendTo(dialog.getFoot());
	    	}
	    }
	 } );
	 
	 // 帮助信息插件 add by l00195395
	 Ccay.UI.XControl.addPlugin( "XDialog", "infoTip", {
	    preInit: function ( dialog, op ) {
	    	if(op.infoTip){
				op.showFoot = false;
				// 在body下生成
				op.target = document.body;
		    	//保持单实例
		    	var infoTip = $("#ccay_infoTip");
		    	if( infoTip.length > 0 ){
		    		infoTip.manager().close();
		    	}
	    	}
	    },
	    build : function( dialog, op ) {
	    	// 锁定按钮
	    	if(op.infoTip){
		    	var pinBtn = $("<div class='ccay-dialog-pin' title='{0}'><div class='ccay-dialog-pinimg' ></div></div>".formatValue($i18n("ccay.common.infotip.pin")));
				dialog.getHead().find(".ccay-dialog-title").before(pinBtn);
				pinBtn.click(function(){
					$(this).children().toggleClass("pin");
					dialog.dom.toggleClass("pin");
				})
	    	}
	    }
	 } );

} )( Ccay.UI.XDialog );

